/**
 * Created by hjqi on 2016/8/30.
 */
angular.module('NatureCloud').factory('clusterService', function ($http) {
    return {
        createCluster:function(name){
            var _data = {
                name:name
            }
            return $http.post('/cluster/create', _data).then(function (response) {
                return response;
            });
        },
        deleteCluster:function(clusterId){
            var _data = {
                clusterId:clusterId
            };
            return $http.post('/cluster/delete', _data).then(function (response) {
                return response;
            });
        },
        getClustersInfo:function(clusterId){
            var _url  = '/cluster/get';
            if(clusterId !== undefined)
                _url += '?clusterId='+clusterId;

            return $http.get(_url).then(function (response) {
                return response;
            });
        },
        checkNode:function(clusterId,token){
            var _data = {
                clusterId:clusterId,
                token:token
            }
            return $http.post('/cluster/checkNode',_data).then(function (response) {
                return response;
            });
        },
        getClusterToken:function(clusterId){
            return $http.get('/cluster/getClusterToken?clusterId='+clusterId).then(function (response) {
                return response;
            });
        },
        getNodeInfoByPage:function(clusterId,nodes){
            var _data = {
                clusterId:clusterId,
                nodes:nodes
            }
            return $http.post('/cluster/getNodeInfoByPage', _data).then(function (response) {
                return response;
            });
        },
        getNodeInfo:function(clusterId){
            var _data = {
                clusterId:clusterId
            }
            return $http.post('/cluster/getNodeInfo', _data).then(function (response) {
                return response;
            });
        },
        deleteClusterNode:function(clusterId,nodeId){
            var _data = {
                clusterId:clusterId,
                nodeId:nodeId
            }
            return $http.post('/cluster/deleteNode', _data).then(function (response) {
                return response;
            });
        }
    }
});